﻿

goog.provide('ol.dmp.interactionGeometry.SimplyArrow');


goog.require('ol.dmp.interactionGeometry.Base');


ol.dmp.interactionGeometry.SimplyArrow = function (options)
{
    this.maxPointsPerSketch_ = 2;
    goog.base(this, options);
}

goog.inherits(ol.dmp.interactionGeometry.SimplyArrow, ol.dmp.interactionGeometry.Base);


ol.dmp.interactionGeometry.SimplyArrow.prototype.atFinish = function (event)
{
   return (this.keyPoints_.length+1) == this.maxPointsPerSketch_;
};

ol.dmp.interactionGeometry.SimplyArrow.prototype.startDrawing = function (event)
{
    var start = event.coordinate;
    this.finishCoordinate_ = start;
    this.keyPoints_.push(start);

    var polygonPoints = [this.keyPoints_.slice()];
    geometry = new ol.geom.Polygon(polygonPoints);
    this.sketchFeature_ = new ol.Feature();
    this.sketchFeature_.setGeometry(geometry);
    
    var llinePoints = this.keyPoints_.slice();
    this.sketchLine_ = new ol.Feature(new ol.geom.LineString(llinePoints));

};

ol.dmp.interactionGeometry.SimplyArrow.prototype.modifyDrawing = function (event)
{
    var coordinate = event.coordinate;
    var geometry = this.sketchFeature_.getGeometry();
    var sketchLineGeom = this.sketchLine_.getGeometry();
    var polygonPoints = this.keyPoints_.slice();
    polygonPoints.push(coordinate);

    if (polygonPoints.length == this.maxPointsPerSketch_)
    {
        var simplyArrwoPoints = ol.dmp.algorithmsUtility.simplyArrow(polygonPoints)
        sketchLineGeom.setCoordinates(simplyArrwoPoints);
        geometry.setCoordinates([simplyArrwoPoints]);
    }

};

